package com.itheima.common;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @Author itheima
 * @Date 2022/4/29 16:04
 */
@WebFilter("/*")
public class MyFilter implements Filter {
    /*
      web工程一启动就会调用该init方法初始化过程
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("MyFilter.init");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("MyFilter.doFilter");
        //放行
        chain.doFilter(request, response);
    }

    /**
     * web工程服务器关闭，则会调用destroy销毁
     */
    @Override
    public void destroy() {
        System.out.println("MyFilter.destroy");
    }
}
